//
//  NSDate+Extension.m
//  DDFish
//
//  Created by 糖otk on 2017/8/15.
//  Copyright © 2017年 Burining. All rights reserved.
//

#import "NSDate+Extension.h"

@implementation NSDate (Extension)
- (NSString *)fixStringForDate: (NSString *)dateFormat
{
    NSDateFormatter* dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateStyle:NSDateFormatterFullStyle];
    [dateFormatter setDateFormat:dateFormat];
    NSString *fixString = [dateFormatter stringFromDate:self];
    return fixString;
}



+(NSString *)DateWithinterger:(NSInteger)date
{
    NSDate *dateM = [self getDateFromUnixTimestamp:date];
    
    NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
    formatter.dateFormat = @"yyyy-MM-dd HH:mm";
    
    return [formatter stringFromDate:dateM];
}

+(NSString *)DateYearMountDayWithinterger:(NSInteger)date
{
    NSDate *dateM = [self getDateFromUnixTimestamp:date];
    
    NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
    formatter.dateFormat = @"yyyy-MM-dd";
    
    return [formatter stringFromDate:dateM];
}

+(NSString *)DateDayWithinterger:(NSInteger)date
{
    NSDate *dateM = [self getDateFromUnixTimestamp:date];
    
    NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
    formatter.dateFormat = @"yyyy/MM/dd";
    
    return [formatter stringFromDate:dateM];
}


+(NSString *)DateStingWithinterger:(NSInteger)date
{
    NSDate *dateM = [self getDateFromUnixTimestamp:date];
    
    NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
    formatter.dateFormat = @"yyyy/MM/dd HH:mm";
    
    return [formatter stringFromDate:dateM];
}

+(NSDate*)getDateFromUnixTimestamp:(NSInteger)unixTimestamp{
    NSDate* dat = [NSDate dateWithTimeIntervalSince1970:unixTimestamp];
    return dat;
}

+(NSString *)DateOtherWithinterger:(NSInteger)date
{
    NSDate *dateM = [self getDateFromUnixTimestamp:date];
    
    NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
    formatter.dateFormat = @"yyyy/MM/dd";
    
    return [formatter stringFromDate:dateM];
}

+(NSInteger)getTimeDay {
    NSDate  *currentDate = [NSDate date];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:currentDate];
    
    NSInteger year=[components year];
    NSInteger month=[components month];
    NSInteger day=[components day];
    NSLog(@"currentDate = %@ ,year = %ld ,month=%ld, day=%ld",currentDate,year,month,day);
    return day;
}
@end
